package ebusiness.ebusiness.Dao;

import ebusiness.ebusiness.Dao.Comment.CommentQuery;
import ebusiness.ebusiness.Dao.GoodsDao.GoodQuery;
import ebusiness.ebusiness.Dao.OrderDao.OrderInter;
import ebusiness.ebusiness.Dao.TorlleyDao.TorlleyInter;
import ebusiness.ebusiness.Dao.WalletDao.WalletQuery;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class DBManager {
    private static SqlSessionFactory factory;


    public DBManager() {

    }
    public static void DBinit() throws  IOException{
        if(factory==null){
            InputStream in = Resources.getResourceAsStream("dbconfig.xml");
             factory=new SqlSessionFactoryBuilder().build(in);

        }
    }
    public static SqlSessionFactory GetSqlFactory() throws Exception{
        if(factory==null)DBinit();
        if(factory==null) throw new Exception("fail to init database");
        return factory;
    }

}
